package com.hontech.libratest.activity.fragment.sub

import android.graphics.Color
import android.view.View
import android.widget.TextView
import com.hontech.libratest.R
import com.hontech.libratest.model.RkcStatus
import com.hontech.libratest.utils.isBitSet

class RkcStatusSub (view: View) {

    private val tvs = arrayOf(
        view.findViewById<TextView>(R.id.id_rkc_sw_0),
        view.findViewById<TextView>(R.id.id_rkc_sw_1),
        view.findViewById<TextView>(R.id.id_rkc_sw_2),
        view.findViewById<TextView>(R.id.id_rkc_sw_3),
        view.findViewById<TextView>(R.id.id_rkc_sw_4),
        view.findViewById<TextView>(R.id.id_rkc_sw_5),
        view.findViewById<TextView>(R.id.id_rkc_sw_6),
        view.findViewById<TextView>(R.id.id_rkc_sw_7),
        view.findViewById<TextView>(R.id.id_rkc_sw_8),
        view.findViewById<TextView>(R.id.id_rkc_sw_9),
        view.findViewById<TextView>(R.id.id_rkc_sw_10),
        view.findViewById<TextView>(R.id.id_rkc_sw_11),
        view.findViewById<TextView>(R.id.id_rkc_sw_12),
        view.findViewById<TextView>(R.id.id_rkc_sw_13),
        view.findViewById<TextView>(R.id.id_rkc_sw_14),
        view.findViewById<TextView>(R.id.id_rkc_sw_15)
    )

    private val tvTemp = view.findViewById<TextView>(R.id.id_rkc_tv_temp)

    fun update() {
        val s = RkcStatus.instance
        val sw = s.sw.value
        for (i in 0..15) {
            val ret = sw.isBitSet(i)
            tvs[i].text = if (ret) "有效" else "无效"
            tvs[i].setTextColor( if (ret) Color.RED else Color.BLUE )
        }
        tvTemp.text = "${s.temp.signedValue()}℃"
    }

}